package com.example.minefieldkeepercloud.activity.dailypower;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import android.view.View;
import android.widget.ListView;

import com.example.minefieldkeepercloud.R;

import com.example.minefieldkeepercloud.adapter.DailyPowerDetailAdapter;

import com.example.minefieldkeepercloud.bean.DailyPowerDetailBean;

import com.example.minefieldkeepercloud.interfac.ApiHttpCallback;

import com.example.minefieldkeepercloud.network.MyGson;
import com.example.minefieldkeepercloud.network.NetHelperNew;
import com.example.minefieldkeepercloud.util.NetWorkUtil;
import com.example.minefieldkeepercloud.util.ToastUtil;

import java.util.ArrayList;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DailyPowerDetailAc extends AppCompatActivity {
    @BindView(R.id.recyleview)
    ListView recyleview;
    private DailyPowerDetailAdapter dailyPowerAdapter;
    private List<DailyPowerDetailBean.DataBean> listData;

    public static void start(Activity mactivity, String factoryID, String userID,String bzl,String time_vale) {
        Intent intent = new Intent(mactivity, DailyPowerDetailAc.class);
        intent.putExtra("factoryID", factoryID);
        intent.putExtra("userID", userID);
        intent.putExtra("bzl", bzl);
        intent.putExtra("time_vale", time_vale);
        mactivity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_dailypowerdetail);
        ButterKnife.bind(this);
        init();
        getNetData();
    }

    private void init()
    {
        listData = new ArrayList<>();
        dailyPowerAdapter = new DailyPowerDetailAdapter(DailyPowerDetailAc.this, listData);
        recyleview.setAdapter(dailyPowerAdapter);

    }

    private void getNetData()
    {
        if (!NetWorkUtil.check(this)) {
            return;
        }
        NetHelperNew.GetCalPoweStatistics_Detail_Table(getIntent().getStringExtra("factoryID"), getIntent().getStringExtra("userID"), getIntent().getStringExtra("bzl"), getIntent().getStringExtra("time_vale"), new ApiHttpCallback(DailyPowerDetailAc.this,1,true) {
            @Override
            public void onSuccess(String data) {
                DailyPowerDetailBean dailyPowerDetailBean = MyGson.getInstance().fromJson(data, DailyPowerDetailBean.class);
                if (dailyPowerDetailBean.getType() == 1) {
                    if (dailyPowerDetailBean.getData().size() > 0) {
                        listData=dailyPowerDetailBean.getData();
                        dailyPowerAdapter.setListData(listData);
                        dailyPowerAdapter.notifyDataSetChanged();
                    } else {
                        ToastUtil.showToast(DailyPowerDetailAc.this, "没有相关数据");
                    }

                } else {
                    ToastUtil.showToast(DailyPowerDetailAc.this, dailyPowerDetailBean.getContent());
                }
            }
        });

    }


    @OnClick({R.id.title_left})
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.title_left:
                finish();
                break;
        }
    }
}
